#include <cassert>
#include "BinaryExpr.h"
#include "MosParser.h"

using namespace moses;

BinaryExpr::BinaryExpr(Expr *pLeft, int op, Expr *pRight)
	: m_pLeft(pLeft), m_op(op), m_pRight(pRight)
{

}

BinaryExpr::~BinaryExpr()
{

	delete m_pLeft;
	delete m_pRight;

}

Value BinaryExpr::Evaluate(Runtime *pEnv)
{
	switch (m_op)
	{
		case T_PLUS:	return m_pLeft->Evaluate(pEnv) + m_pRight->Evaluate(pEnv);
		case T_MINUS:	return m_pLeft->Evaluate(pEnv) - m_pRight->Evaluate(pEnv);
		case T_MUL:		return m_pLeft->Evaluate(pEnv) * m_pRight->Evaluate(pEnv);
		case T_DIV:		return m_pLeft->Evaluate(pEnv) / m_pRight->Evaluate(pEnv);
		default:		assert(false); return Value(Type::NONE);
	}

}
